package com.zx.map.dao.impl;

import com.zx.map.dao.OrdLogDao;
import com.zx.map.dao.mapper.OrdLogMapper;
import com.zx.map.dao.mapper.UtilsMapper;
import com.zx.map.dao.model.OrdLog;
import com.zx.map.dao.model.OrdLogExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 14-3-1
 * Time: 上午10:54
 * To change this template use File | Settings | File Templates.
 */
@Component("OrdLogDao")
public class OrdLogImpl implements OrdLogDao {

    @Autowired
    private OrdLogMapper mapper;
    @Autowired
    private UtilsMapper utilsMapper;

    /**
     * 新增
     */
    public String add(OrdLog ordLog) throws DataAccessException {
        int column = mapper.insert(ordLog);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return ordLog.getOrdId();
    }

    /**
     * 修改
     * @param ordLog
     * @return
     * @throws DataAccessException
     */
    public String update(OrdLog ordLog) throws DataAccessException {
        int column = mapper.updateByPrimaryKeySelective(ordLog);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return ordLog.getOrdId();
    }

    /**
     * 删除
     */
    public void delete(OrdLog ordLog) throws DataAccessException {
        int column = mapper.deleteByPrimaryKey(ordLog.getOrdId());
        if (column != 1) {
            throw new RuntimeException("");
        }
    }

    /**
     * 分页查找
     */
	public List<OrdLog> getPageByExample(int pageSize, int pageBegin,
			OrdLogExample example) throws DataAccessException {
		return mapper.getPageByModel(pageSize, pageBegin, example); 
	}
	/**
	 * 查找条数
	 * 
	 * @param example
	 * @return
	 * @throws DataAccessException
	 */
	public int countByExample(OrdLogExample example) throws DataAccessException {
		return mapper.countByExample(example);
	}

	/**
	 * 
	 */
	public List<OrdLog> getListByExample(OrdLogExample example)
			throws DataAccessException {
		return mapper.selectByExample(example); 
	}

	public OrdLog selectByPrimaryKey(String key) throws DataAccessException {
		return mapper.selectByPrimaryKey(key);
	}

	@Override
	public OrdLog selectByPrimaryKeyAndLineLock(String key) throws DataAccessException {
		return mapper.selectByPrimaryKeyAndLineLock(key);
	}


	public Double geGatheringAmt() throws DataAccessException {
		return utilsMapper.geGatheringAmt();
	}

	public Double geBackAccountAmt() throws DataAccessException {
		return utilsMapper.geBackAccountAmt();
	}

	public Double geSettleAmt() throws DataAccessException {
		return utilsMapper.geSettleAmt();
	}

	public Double geT0Amt() throws DataAccessException {
		return utilsMapper.geT0Amt();
	}
	public Integer geSettleCount() throws DataAccessException{
		return utilsMapper.geSettleCount();
	}
	public Integer geGatheringCount() throws DataAccessException{
		return utilsMapper.geGatheringCount();
	}

	@Override
	public Integer geGatheringCountByAgent(List values)
			throws DataAccessException {
		return utilsMapper.geGatheringCountByAgent(values);
	}

	@Override
	public Double geGatheringAmtByAgent(List values) throws DataAccessException {
		return utilsMapper.geGatheringAmtByAgent(values);
	}

	@Override
	public Double getPaymentAmt(OrdLogExample example)
			throws DataAccessException {
		return mapper.getPaymentAmt(example);
	}

	@Override
	public List<Map<String, Object>> orderAnalysis(OrdLogExample example)  throws DataAccessException{
		return mapper.orderAnalysis(example);
	}
	
	@Override
	public int countTodayNewMembers(String merchantId, String createDate, String endDate, String transStatus)  throws DataAccessException{
		return mapper.countTodayNewMembers(merchantId, createDate, endDate, transStatus);
		
	}
	
	@Override
	public int countTodayAllMembers(OrdLogExample example)  throws DataAccessException{
		return mapper.countTodayAllMembers(example);
	}
	
	@Override
	public List<Map<String, Object>> groupbyType(OrdLogExample example, String analysisType, String groupbyType) throws DataAccessException{
		return mapper.tradeAnalysis(example, analysisType, groupbyType);
	}
	@Override
	public long getUsers(OrdLogExample example)   throws DataAccessException{
		return mapper.getUsers(example);
	}
}
